package com.example.cunion.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.cunion.entity.RotationChart;
import com.example.cunion.entity.RotationChart;
import com.example.cunion.exception.CunionException;
import com.example.cunion.service.RotationChartService;
import com.example.cunion.mapper.RotationChartMapper;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* @author Aero
* @description 针对表【rotation_chart(轮播图表)】的数据库操作Service实现
* @createDate 2023-10-03 14:32:22
*/
@Service
public class RotationChartServiceImpl extends ServiceImpl<RotationChartMapper, RotationChart>
    implements RotationChartService{
    @Resource
    private RotationChartMapper rotationChartMapper;

    @Override
    public ArrayList<HashMap> searchAllRotationChart() {
        //调用rotationChartMapper的searchAllRotationChart()方法，获取所有的旋转图表
        ArrayList<HashMap> list = rotationChartMapper.searchAllRotationChart();
        //返回获取的旋转图表
        return list;
    }

    @Override
    public Integer addRotationChartByMp(RotationChart rotationChart) {
        int insert = rotationChartMapper.insert(rotationChart);
        if (insert != 1){
            throw new CunionException("添加失败");
        }
        return insert;
    }

    @Override
    public Integer deletedRotationChartByMp(String rotationChartId) {
        int result = rotationChartMapper.deleteById(rotationChartId);
        if (result != 1){
            throw new CunionException("删除失败！");
        }
        return result;
    }

    @Override
    public Integer updateRotationChartByMp(RotationChart rotationChart) {
        int result = rotationChartMapper.updateById(rotationChart);
        if (result != 1){
            throw new CunionException("修改失败");
        }
        return result;
    }

    @Override
    public List<RotationChart> searchRotationChartByMp(Integer start, Integer length) {
        Page<RotationChart> page = new Page<>(start, length);
        QueryWrapper<RotationChart> QueryWrapper = new QueryWrapper<>();
        Page<RotationChart> selectPage = rotationChartMapper.selectPage(page, QueryWrapper);
        List<RotationChart> list = selectPage.getRecords();
        return list;
    }
}




